package com.ruoyi.project.storage.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.storage.domain.Address;
import com.ruoyi.project.storage.domain.vo.OrderVO;
import com.ruoyi.project.storage.domain.vo.BoxStandardVO;
import com.ruoyi.project.storage.service.IAddressService;
import com.ruoyi.project.storage.service.IBoxStandardService;
import com.ruoyi.project.storage.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 空箱预约Controller
 *
 * @author mengyuanqing
 * @date 2020/5/12
 */
@RestController
@RequestMapping("app/box")
@Api(tags = {"【手机端】5.2.3 空箱预约"},description = "获取当前用户默认收货地址、有效箱子规格选择（非分页）、预约")
public class AppBoxController extends BaseController {
    // 注入订单Service
    @Autowired
    private IOrderService orderService;
    // 注入箱子规格Service
    @Autowired
    private IBoxStandardService boxStandardService;
    // 注入地址Service
    @Autowired
    private IAddressService addressService;
    /**
     * 查询当前用户默认地址
     *
     * @return 结果
     */
    @Log(title = "5.2.3.1 获取当前用户默认收货地址", businessType = BusinessType.OTHER)
    @GetMapping("/defaultAddress")
    @ApiOperation(value = "5.2.3.1 获取当前用户默认收货地址", notes = "查询当前用户默认地址")
    public AjaxResult defaultAddress(){
        // 实例化地址对象
        Address address = new Address();
        // 设置只查询当前用户默认地址
        address.setIsDefault(0);
        // 设置当前用户id
        address.setUserId(SecurityUtils.getUserId());
        // 返回成功消息
        AjaxResult ajax=AjaxResult.success();
        // 用户默认地址放入map
        ajax.put("data",addressService.selectDefaultAddress(address));
        // 返回响应结果
        return ajax;
    }
    /**
     * 查询当前可用箱子规格
     *
     * @return 结果
     */
    @Log(title = "5.2.3.2 有效箱子规格选择（非分页）", businessType = BusinessType.OTHER)
    @GetMapping("/standard/select")
    @ApiOperation(value = "5.2.3.2 有效箱子规格选择（非分页）", notes = "选择有效的规格")
    public AjaxResult standard(){
        // 实例化对象
        BoxStandardVO boxStandardVO = new BoxStandardVO();
        // 返回通用实体(非分页)
        return AjaxResult.success(boxStandardService.selectBoxStandardEffective(boxStandardVO));
    }
    /**
     * 预约
     *
     * @return 结果
     */
    @Log(title = "5.2.3.3 预约", businessType = BusinessType.INSERT)
    @PostMapping("/order")
    @ApiOperation(value = "5.2.3.3 预约", notes = "预约")
    public AjaxResult add(@RequestBody OrderVO orderVO) {
        //返回响应结果
        return toAjax(orderService.insertOrderList(orderVO));
    }
}
